#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
#define MAXN 40005

int T, Cas = 1, num;

char op[2];

int c[MAXN], cnt;

void work() {
	memset(c, 0, sizeof(c));
	cnt = 0;
	printf("Case %d:\n", Cas ++);
	for (int i = 1; i <= T; i ++) {
		scanf("%s %d", op, &num);
		if (op[0] == 'A') {
			int minans = num + 1, res = 0;
			if (cnt == 0) {
				printf("-1\n"); continue;
			}
			for (int j = cnt; j >= 1; j --) {
				int r = c[j] % num;
				if (minans > r) {
					minans = r;
					res = j;
				}
			}
			printf("%d\n", res);
		} else {
			c[++ cnt] = num;	
		}
	}
}

bool flag = false;

int main() {
	while (scanf("%d", &T) != EOF) {
		if (T == 0) {
			break;
		}
		if (flag) {
			printf("\n");
		}
		flag = true;
		work();
	}
	return 0;
}
